﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using KeaoBase;

namespace KeaoMDS.Weight
{
    public partial class SheZhiQuXiang : BaseForm
    {
        public SheZhiQuXiang()
        {
            InitializeComponent();
            BindInfo();
        }

        private void BindInfo()
        {
            if (tabControl1.SelectedTab.Text == "路基")
            {
                Dictionary<string, string> orderBys = new Dictionary<string, string>();
                orderBys.Add("gongcheng", "asc");
                orderBys.Add("zuoyoufu", "asc");
                orderBys.Add("gonglihao1", "asc");
                string createCondition = KeaoUtils._DB.CreateAndCondition("biaoduanleixing", DataValueCommonType.字符串, "路基", "", SearchConditionType.等于);
                createCondition += KeaoUtils._DB.CreateAndCondition("riqi", DataValueCommonType.日期时间, date_kaishishijian.Value.ToString("yyyy-MM-dd 00:00:00"), date_kaishishijian.Value.ToString("yyyy-MM-dd 23:59:59"), SearchConditionType.between);
                DataTable Dt1 = KeaoUtils._DB.GetDataTableByCondition("tbl_biaoduan", createCondition, orderBys);
                foreach (DataRow row in Dt1.Rows)
                {
                    row["biaoduanmingcheng"] = string.Format("{0}_{1}_{2}", row["gongcheng"], row["zuoyoufu"], row["biaoduanmingcheng"]);
                }
                cmb_quxiang.DisplayMember = "biaoduanmingcheng";
                cmb_quxiang.ValueMember = "id";
                cmb_quxiang.DataSource = Dt1;
            }
            if (tabControl1.SelectedTab.Text=="其他")
            {
                string createCondition = KeaoUtils._DB.CreateAndCondition("biaoduanleixing", DataValueCommonType.字符串, "其他", "", SearchConditionType.等于);
                DataTable Dt2 = KeaoUtils._DB.GetDataTableByCondition("tbl_biaoduan", createCondition);
                cmb_quxiang_qita.DisplayMember = "biaoduanmingcheng";
                cmb_quxiang_qita.ValueMember = "id";
                cmb_quxiang_qita.DataSource = Dt2;
            }
        }

        public string m_QuXiangBianHao = string.Empty;

        private void menu_btn_baocun_Click(object sender, EventArgs e)
        {
            if (tabControl1.SelectedTab.Text=="路基")
            {
                m_QuXiangBianHao = string.Format("{0}", cmb_quxiang.SelectedValue);
                DialogResult = DialogResult.OK;
            }
            if (tabControl1.SelectedTab.Text=="其他")
            {
                m_QuXiangBianHao = string.Format("{0}", cmb_quxiang_qita.SelectedValue);
                DialogResult = DialogResult.OK;
            }
        }

        private void menu_btn_guanbi_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void SheZhiQuXiang_Load(object sender, EventArgs e)
        {
            m_QuXiangBianHao = string.Empty;
        }

        private void date_kaishishijian_ValueChanged(object sender, EventArgs e)
        {
            BindInfo();
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindInfo();
        }
    }
}
